class Solution {
public:
    void QuickSort(vector<int>& nums, int begin, int end)
    {
        if (begin >= end)
            return;

        int key = nums[rand() % (end - begin + 1) + begin];
        int left = begin - 1, right = end + 1, i = begin;

        while (i < right)
        {
            if (nums[i] < key) swap(nums[++left], nums[i++]);
            else if (nums[i] > key) swap(nums[--right], nums[i]);
            else i++;
        }

        QuickSort(nums, begin, left);
        QuickSort(nums, right, end);
    }

    vector<int> sortArray(vector<int>& nums) {
        srand(time(NULL));
        QuickSort(nums, 0, nums.size() - 1);
        return nums;
    }
};